package logic

import (
	"context"
	"gorm.io/gorm"
	"user-management/model/mysql"
	"user-management/userrpc/internal/svc"
	"user-management/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserUpdateLogic {
	return &UserUpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserUpdateLogic) UserUpdate(in *userrpc.UpdateRequest) (*userrpc.UpdateResponse, error) {
	// todo: add your logic here and delete this line
	user := mysql.User{
		Model:    gorm.Model{ID: uint(in.Id)},
		Account:  in.Account,
		Password: in.Password,
	}
	mysql.DB.Debug().Updates(&user)
	return &userrpc.UpdateResponse{
		Id: int64(user.ID),
	}, nil
}
